package core.net;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

class ConnectionHandler {
    private static String urlString = "http://chalmersverateam.se/XMLData.php";
	
    private static ConnectionHandler instance;
    //Prevent instantiation, class is singleton.
    private ConnectionHandler(){
    }
    
    /**
     * Returns the singleton instance of the class.
     * @return The singleton instance of the class.
     */
    public static ConnectionHandler getInstance(){
    	if (instance == null){
    		instance = new ConnectionHandler();
    	}
    	return instance;
    }
    
    /**
     * Returns a continuous stream of data representing an XML document containing log data from webserver.
     * @return A continuous stream of data representing an XML document containing log data from webserver.
     * @throws IOException If a connection error is encountered.
     */
    InputStream getDataStream(int startIndex) throws IOException{
    	urlString = "http://chalmersverateam.se/XMLData.php?id=" + startIndex;
		return new URL(urlString).openConnection().getInputStream();
    }
}
